package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.ProtocolConst;
import com.xgkj.diyiketang.data.RankingInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Tao on 2017/4/27.
 */

public class RankingTask extends CouponHttpBaseTask{

    public RankingTask(){

    }
    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject respJson = response.getBody();
        List<RankingInfo> list = new ArrayList<>();
        if (respJson != null){
            list = JSON.parseArray(
                    respJson.getString(ProtocolConst.LIST_TAG),
                    RankingInfo.class);
        }
        notifyTaskCompleted(TaskResultCode.SUCCESS, list);
    }

    @Override
    protected void prepareRequest() {
        if (mPhase == TASK_PHASE_INIT){
            CouponHttpRequest request = new CouponHttpRequest(
                    RequestType.ADVERTISEMENT_REQUEST);
            JSONObject json = new JSONObject();
            request.setData(json.toString());
            request.setApiNo(ApiNo.USERlISTS);
            addRequest(request);
        }
    }

}
